package com.maweis;

import javax.swing.*;

/**
 * form for component to set the parameters
 *
 * @author peter
 */
public class BlogDefineForm {
    private JPanel rootComponent;
    private JTextField urlField;
    private JTextField nameField;
    private JPasswordField passwordField;

    public BlogDefineForm() {
        urlField.setText("Please input your blog url here.");
    }

    public JComponent getRootComponent() {
        return rootComponent;
    }


    /**
     * get data from component
     *
     * @param component component
     */
    public void getDataFrom(BlogApplicationComponent component) {
        urlField.setText(component.url);
        nameField.setText(component.username);
        passwordField.setText(component.password);
    }

    /**
     * save data to component
     *
     * @param component component
     */
    public void saveDataTo(BlogApplicationComponent component) {
        component.url = urlField.getText();
        component.username = nameField.getText();
        component.password = new String(passwordField.getPassword());
    }


    public boolean isModified(BlogApplicationComponent data) {
        return urlField.getText() != null ?
                !urlField.getText().equals(data.getUrl()) :
                data.getUrl() != null;
    }
}
